<template>
	<div id="companyLogin" class="login_bg">
		<common-login :commonData="{$parent:$parent}"></common-login>
		<div class="login_box">
			<ul class="text_center login_box_ul">
				<li>
					<router-link to="/login">个人登录</router-link>
				</li>
				<li>
					<router-link class="login_tab_active" to="/company_login">企业登录</router-link>
				</li>
			</ul>
			<form class="login_form" ref="form" :model="form" @keyup.enter="toCompanyLogin(form)">
				<div style="background-image: url(/static/img/login/download.png);background-size: 100% 100%;margin-top: -90px;height: 300px;">

                </div>
				<div class="login_btn_box text_center">
					<a class="login_btn" target="_blank" :href="api.config.downloadUrl">立即下载</a>
					<!-- <a class="login_btn" @click="toCompanyLogin(form)">立即下载</a> -->
					<router-link class="login_a" to="/company_forget">忘记密码</router-link><span>|</span>
					<router-link class="login_a" to="/company_register">点击注册</router-link>
				</div>
			</form>
		</div>
	</div>
</template>

<script>
	import commonLogin from '../components/c_login.vue'
	export default {
		name: 'company_login',
		data() {
			return {
				base64Code: "",

				form: {
					telephone: "",
					pwd: "",
					code: "",
					v_token: ""
				}
			}
		},
		created: function() {

		},
		mounted: function() {
			this.getImgCode();
		},
		methods: {
			clickCodeImg: function() {
				this.getImgCode();
			},
			toCompanyLogin: function(dataForm) {
				var that = this;
				if (dataForm.telephone == "") {
					this.$message.error('请输入手机号！');
					return;
				}
				if (dataForm.pwd == "") {
					this.$message.error('请输入密码！');
					return;
				}
				if (dataForm.code.length != 4) {
					this.$message.error('请输入正确的验证码！');
					return;
				}
				this.common.post(this.api.companyLogin, dataForm, function(data) {
					that.$message.success("恭喜您登陆成功！");
					that.$cookies.set("loginInfo", data.resultMap, 30 * 60); // 设置cookie中存放的生命周期
					that.$cookies.set("token", data.resultMap.token, 30 * 60); // 设置cookie中存放的生命周期
					that.$parent.loginInfo = data.resultMap;
					that.common.toPage('/home', true);
				}, function(error) {
					that.getImgCode();
					that.$message.error(error.resultMsg);
				});
			},
			getImgCode: function() {
				var that = this;
				this.common.post(this.api.verifyCode, {}, function(data) {
					that.base64Code = data.base64;
					that.form.v_token = data.v_token;
				}, function(error) {
					that.$message.error(error.resultMsg);
				});
			}
		},
		components: {
			"common-login": commonLogin
		}
	}
</script>
<style>
</style>
